#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

const int N = 2e5 + 10;

int n, m;
vector<int> q;
int cnt;
struct QUery
{
    int a, b;
    bool w;
}query[N];
int p[N], d[N];


int f(int x){
    int l = 0, r = cnt;
    while(l < r){
        int mid = (l + r) >> 1;
        if(q[mid] >= x){
            r = mid;
        }else{
            l = mid + 1;
        }
    }

    return l;
}

int find(int x){
    if(x != p[x]){
        int root = find(p[x]);
        d[x] += d[p[x]];
        p[x] = root;
    }

    return p[x];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    for(int i = 0; i < N; i ++) p[i] = i;

    cin >> n >> m;

    for(int i = 0; i < m; i ++){
        int a, b;
        string op;
        cin >> a >> b >> op;

        q.push_back(a - 1);
        q.push_back(b);

        if(op == "even"){
            query[i].a = a - 1;
            query[i].b = b;
            query[i].w = true;
        }else{
            query[i].a = a - 1;
            query[i].b = b;
            query[i].w = false;
        }   
    }

    sort(q.begin(), q.end());
    q.erase(unique(q.begin(), q.end()), q.end());
    cnt = q.size() - 1;

    // for(int i = 0; i <= cnt; i ++) cout << q[i] <<  " ";
    // cout << endl << "-----------------------------------------" << endl;

    // for(int i = 0; i < m; i ++){
    //     cout << f(query[i].a) << " " << f(query[i].b) << "  " << query[i].w <<  endl;
    // }

    // cout << endl;



    int res = 0;
    bool ans = true;


    for(int i = 0; i < m; i ++){
        if(!ans) break;

        int a = f(query[i].a), b = f(query[i].b);
        bool flag = query[i].w;


        if(flag){
            int pa = find(a), pb = find(b);
            if(pa == pb){
                if((d[a] + d[b]) % 2 == 1){
                    res = i;
                    ans = false;
                    break;
                }
            }else{
                d[pb] = 0;
                p[pb] = d[a] ^ d[b] ^ 0 ;
            }
        }else{
            int pa = find(a), pb = find(b);
            if(i == m - 1){
                cout << a << " " << b << endl;
                cout << pa << " " << pb << endl;
                cout << d[a] << " " << d[b] << endl;
            }

            if(pa == pb){
                if((d[a] + d[b]) % 2 == 0){
                    res = i;
                    ans = false;
                    break;
                }
            }else{
                d[pb] = d[a] ^ d[b] ^ 1;
                p[pb] = p[pa];
            }
        }
    }


    if(!ans) cout << res << endl;
    else cout << m << endl;

    return 0;
}